package com.mls.fivedistrict.controller.backend;

import com.mls.fivedistrict.common.ServiceResponse;
import com.mls.fivedistrict.controller.BaseController;
import com.mls.fivedistrict.pojo.RecordForExcel;
import com.mls.fivedistrict.server.ExcelService;
import net.sf.json.JSONArray;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/manager")
public class ExcelController extends BaseController {
    @Resource(name = "excelService")
    private ExcelService excelService;

    @PutMapping("/v1/excel/importIntegral")
    public ServiceResponse BatchAddIntegral(@RequestBody Map<String, Object> maps) {
        try {
            String change_reason = (String) maps.get("change_reason");
            String integralId = (String) maps.get("integralId");
            JSONArray jsonArray = JSONArray.fromObject(maps.get("data"));
            List<RecordForExcel> recordForExcelList = JSONArray.toList(jsonArray, RecordForExcel.class);
            ServiceResponse response = excelService.batchInsert(recordForExcelList);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

}

